var dataNum = [1, 1, 6, 16, 18, 2];
$(function() {
	//console.info("in 1");
	loadData();
	
	$(".optionClick").on("click",function(){
		console.info("click");
		loadMessageMain();
	});
	
});

function loadData(){
	//console.info("in 2");
	loadMessageMain();
}

function commonAjaxData(){
	var result = '';
	$.ajax({
		type: 'GET',
		data: jsonData,
	    url: url,
	    async: false,
	    dataType:"json",
	    success: function(data){
	    	result = data;
	    },
	    error: function(){
	    }
	});
	return result;
}

function loadMessageMain(){
	//url = ctx + '/show/degree';
	//jsonData = '';	//jsonData = {startTime:startTime,endTime:endTime};
	//var  returnData= commonAjax();
	//initLineChart(returnData.title,returnData.degree,document.getElementById('messageMain'));
	var subText = $("#subjectSelect").val();
	
	 if (subText=="马克思主义哲学") {
		 dataNum = [1, 6, 12, 16, 8, 2];
	}else if ("高等数学2"==subText) {
		dataNum = [4, 4, 12, 16, 8, 1];
	}else if ("大学体育"==subText) {
		dataNum = [1, 6, 12, 14, 8, 4];
	}else if ("毛泽东思想概论"==subText) {
		dataNum = [1, 7, 16, 10, 8, 2];
	}
   
     
	initLineChart(dataNum,subText,document.getElementById('messageMain'));
}


function initLineChart(data,subText,ele) {
	//console.info("chartssss");
	var myChart = echarts.init(ele); 
	
	var option = {
			   title: {
			        text: '学生考试成绩总览',
		        	subtext: subText
			   },
			   tooltip: {
			       trigger: "item",
			       formatter: "{a} <br/>{b} : {c}"
			   },
			   /*legend: {
			       x: 'left',
			       data: ["2的指数", "3的指数"]
			   },*/
			   xAxis: [
			       {
			           type: "category",
			           name: "x",
			           splitLine: {show: false},
			           data: ['60以下','60-69','70-79','80-89','90-99','100']
			       }
			   ],
			   yAxis: [
			       {
			           type: "text",
			           name: "y"
			       }
			   ],
			    toolbox: {
			       show: true,
			       feature: {
			           mark: {
			               show: false
			           },
			           magicType : {show: true, type: ['line', 'bar']},//, 'stack', 'tiled'
			           dataView: {
			               show: true,
			               readOnly: true
			           },
			           restore: {
			               show: true
			           },
			           saveAsImage: {
			               show: true
			           }
			       }
			   },
			   calculable: true,
			   series: [
			       
			       {
			           name: "人数",
			           type: "line",
			           data: data    //[4, 2, 12, 16, 8, 2]

			       }
			   ]
			};
 
	
	myChart.setOption(option);
}